<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        function myTemplate(id, data) {
            //获取模板的内容  是一个字符串
            var str = document.getElementById(id).innerHTML;
            var pattern = /{{\s*([a-zA-Z]+)\s*}}/;
            var pattResult = null;
            // 循环查找所有的插值 符号
            while ((pattResult = pattern.exec(str))) {
                str = str.replace(pattResult[0], data[pattResult[1]]);
            }
            return str;
        }
    </script>
</body>

</html>